#ifndef __CLUA__
#define __CLUA__

struct lua_State;

#define LuaGlue \
	extern "C" int

extern "C" {
typedef int (*LuaFunctionType)(struct lua_State *pLuaState);
};

#include <map>
#include <string>

namespace LuaRover
{
	class LuaGlobal;
}

namespace umtl
{
	//////////////////////////////////////////////////////////////////////////
	// 

	class cLua
	{
	public:

		typedef std::map< std::string, LuaRover::LuaGlobal* > lua_States;

		cLua();
		virtual ~cLua();

		bool		RunScriptOnly(const char *pFilename);
		bool		RunScript(const char *pFilename, lua_State * context = 0);
		bool		RunString(const char *pCommand);
		const char *GetErrorString(const char* name);
		bool		AddFunction(const char* lua_name, const char *pFunctionName, LuaFunctionType pFunction);
		const char *GetStringArgument(const char* lua_name, int num, const char *pDefault=0);
		double		GetNumberArgument(const char* lua_name, int num, double dDefault=0.0);
		void		PushString(const char* lua_name, const char *pString);
		void		PushNumber(const char* lua_name, double value);

		void		SetErrorHandler(void(*pErrHandler)(const char *pError)) {m_pErrorHandler = pErrHandler;}

		lua_State	*GetScriptContext(const char* lua_name);
		LuaRover::LuaGlobal * FindLuaGlobal(const char* lua_name);

	private:
		//lua_State	*m_pScriptContext;
		LuaRover::LuaGlobal * global_state_;
		lua_States lua_states_; 
		void(*m_pErrorHandler)(const char *pError);
	};

	//////////////////////////////////////////////////////////////////////////
}

#endif